/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.epam.expertsys.web;

import com.epam.expertsys.blogic.Patient;
import com.epam.expertsys.blogic.Request;
import com.epam.expertsys.dbconn.PatientDAOH2;
import com.epam.expertsys.dbconn.RequestDAOH2;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Admin
 */
public class AddRequestServlet extends AbstractServletCommand {

    @Override
    public void process(HttpServletRequest req, HttpServletResponse resp)
            throws SQLException, ServletException, IOException {

        ServletContext servCon = this.getServletContext();

        String login = (String) req.getSession().getAttribute("login");

        String symptomsDescription = req.getParameter("symptomsDescription");
        Long requestDate = (new Date()).getTime();

        PatientDAOH2 patDAO = (PatientDAOH2) servCon.getAttribute("patientDAO");

        Patient pat = patDAO.getPatientByLogin(login);

        Long patientId = pat.getId();

        Request newReq = new Request(null, requestDate, symptomsDescription,
                patientId, null);

        RequestDAOH2 reqDAO = (RequestDAOH2) servCon.getAttribute("requestDAO");

        reqDAO.addRequest(newReq);

        RequestDispatcher respDisp = req.getRequestDispatcher("/auth/index.jsp");
        respDisp.forward(req, resp);

    }
}
